<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>注册 - {{ env('APP_NAME','Laravel') }}</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="{{ asset('/static/layui/css/layui.css') }}">
    <link rel="stylesheet" href="{{ asset('/static/css/login.css') }}">
    <link rel="stylesheet" href="{{ asset('/static/css/override.css') }}">
    <style>
        .app-error-class .jing-layer-content{
            padding: 20px;
            line-height: 25px;
        }
    </style>
</head>
<body>
<div class="layadmin-user-login layadmin-user-display-show app-login" id="LAY-user-login" style="display: none;">
    <div class="layadmin-user-login-main app-register">
        <div class="layadmin-user-login-box layadmin-user-login-header">
            <h4>注册</h4>
        </div>
        <div class="layadmin-user-login-box jing-form">
            <form action="">
                <div class="jing-form-item">
                    <label class="jing-form-label">用户名</label>
                    <div class="jing-input-block">
                        <input type="text" name="username" lay-verify="username" autocomplete="off" placeholder="请输入用户名" class="jing-input">
                    </div>
                </div>
                <div class="jing-form-item">
                    <label class="jing-form-label">密码</label>
                    <div class="jing-input-block">
                        <input type="password" name="password" lay-verify="password" autocomplete="off" placeholder="请输入密码" class="jing-input">
                    </div>
                </div>
                <div class="jing-form-item">
                    <div class="jing-input-block">
                        <button type="button" class="jing-btn jing-btn-fluid" id="submit" lay-submit lay-filter="LAY-user-login-submit">提 交</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <div class="jing-trans layadmin-user-login-footer">
        <p>{{ date('Y') }} 豪情<a href="http://www.Laravel.com/" target="_blank">Laravel Admin</a></p>
    </div>
</div>
@include('admin.common._app_script')
<script>
    var Page = {
        init: function () {
            this.bind()
        },
        bind: function () {
            var self = this

            $('#submit').on('click', function (data) {
                $.ajaxSetup({
                    headers: {
                        'X-CSRF-TOKEN': '{{ csrf_token() }}'
                    }
                });

                $.ajax({
                    url: "{{ route('admin.register.post') }}",
                    type: 'post',
                    data: $('form').serialize(),
                    success: function (data) {
                        if (data.code === 0) {
                            layer.msg('注册成功', {
                                offset: '15px', icon: 1, time: 1000
                            }, function () {
                                location.href = '{{ route('admin.login.get') }}';
                            })

                        } else {
                            layer.msg(data.msg, {
                                offset: '15px', icon: 2, time: 2000
                            })
                        }
                    },
                    error: function (xhr, status, thrown) {
                        console.log(2, xhr)

                        if (xhr.responseText) {
                            self.showError(JSON.parse(xhr.responseText).message)
                        }
                    },
                    statusCode: {
                        422: function(xhr) {
                            alert("page not found");
                        }
                    }
                })

                return false
            })
        },
        showError: function (msg) {
            layer.open({
                // title: '修改密码',
                area: '700px',
                skin: 'app-error-class',
                offset: '200px',
                type: 1,
                content: msg,
                // btn: ['保存', '取消'],
                // closeBtn: true,
                yes: function (index, layero) {
                    // layer.close(index)
                },
                btn2: function (index, layero) {
                    //按钮【按钮二】的回调
                    //return false 开启该代码可禁止点击该按钮关闭
                }
            });
        }
    }

    /*
    form.on('submit(LAY-user-login-submit)', function (data) {
    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': '{{ csrf_token() }}'
            }
        });
        $.post(
            "{{ route('admin.login.post') }}",
            data.field,
            function (data) {
                debugger
                if (data.code === 0) {
                    layer.msg('登录成功', {
                        offset: '15px', icon: 1, time: 1000
                    }, function () {
                        location.href = '{{ route('admin.index') }}';
                        // location.href = ''
                    })

                } else {
                    layer.msg(data.msg, {
                        offset: '15px', icon: 2, time: 2000
                    })
                    $('#captcha_img').attr('src', '/captcha/math?' + Math.random())
                }
            });
    });
    */

    $(function(){
        Page.init()
    })

</script>
</body>
</html>
